<?php

namespace App\Controller\Admin;

use App\Middleware\AdminMiddleware;
use App\Model\QmGameWxTask;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;

#[Controller(prefix: '/admin/WxTask'), Middleware(AdminMiddleware::class)]
class WxTaskController extends BaseController {

    /**
     * 获取列表
     * @return array
     */
    #[GetMapping(path: 'index')]
    public function index(): array {
        $limit = $this->request->query('size', config('apiadmin.admin_list_default'));
        $game_hash = $this->request->query('game_hash', '');
        $openid = $this->request->query('openid', '');
        $status = $this->request->query('status', 0);
        $date = $this->request->query('date', '');

        $listObj = QmGameWxTask::query();
        if ($game_hash) {
            $listObj = $listObj->where('game_hash', $game_hash);
        }
        if ($openid) {
            $listObj = $listObj->where('openid', $openid);
        }
        if ($status >= 0) {
            $listObj = $listObj->where('status', $status);
        }
        if (is_array($date) && !empty($date[0])) {
            $listObj = $listObj->whereBetween('create_date', $date);
        }
        $listObj = $listObj->orderByDesc('created_at')->paginate((int)$limit);

        $return = [
            'list'  => $listObj->items(),
            'count' => $listObj->total()
        ];
        return $this->buildSuccess($return);
    }

}